# -*- coding:utf-8 -*-

from Tkinter import *

root = Tk()
root.wm_title('menu_test')
root.geometry('500x300+0+0') #80x80代表窗口大小，0，0是窗口初始位置(是‘x’不是‘*’)

def create_python():
  Label(root,text = 'python').pack()
def create_c():
  Label(root,text = 'C').pack()
def create_java():
  Label(root,text = 'Java').pack()

menubar = Menu(root)
fmenu = Menu(menubar)
for item in ['新建','打开']:
  fmenu.add_command(label = item)
fmenu.add_separator()   #加分割线
for item in ['保存','另存为']:
  fmenu.add_command(label = item)

emenu = Menu(menubar)
for item in ['复制','粘贴','剪切']:
  emenu.add_command(label = item)

vmenu = Menu(menubar)
for item in ['默认视图','新式视图']:
  vmenu.add_command(label = item)

amenu = Menu(menubar)
for item in ['版权信息','其他说明']:
  amenu.add_command(label = item)

m2 = Menu(root)
for item in ['python','perl','php','ruby']:
  m2.add_checkbutton(label = item)        #checkbutton复选按钮
m2.add_separator()
for item in ['java','c','c++']:
  m2.add_radiobutton(label = item)        #radiobutton单选按钮

#add_cascade添加子菜单
menubar.add_cascade(label = '文件',menu = fmenu)
menubar.add_cascade(label = '编辑',menu = emenu)
menubar.add_cascade(label = '视图',menu = vmenu)
menubar.add_cascade(label = '关于',menu = amenu)
menubar.add_cascade(label = 'lan',menu = m2)
root['menu'] = menubar

#右键菜单
rclick_menu = Menu(root)
rclick_menu.add_command(label = 'C',command = create_c)
rclick_menu.add_command(label = 'Java',command = create_java)
rclick_menu.add_command(label = 'python',command = create_python)
def pop(event):
  rclick_menu.post(event.x_root,event.y_root)
root.bind('<Button-3>',pop)
root.mainloop()